package com.lei2j.templateMethod;

/**
 * Created by lei2j on 2019/1/27.
 */
public abstract class CaffeineBeverage {

    /**
     * 模板方法
     */
    public final void prepareRecipe(){
        boilWater();
        brew();
        pourInCup();

        if(isAddCondiments()){
            addCondiments();
        }
    }

    abstract void brew();

    abstract void addCondiments();

    public void boilWater(){
        System.out.println("boilWater");
    }

    public void pourInCup(){
        System.out.println("pourInCup");
    }


    /**
     * 钩子函数
     * @return
     */
    public boolean isAddCondiments(){
        return true;
    }
}
